package user.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import user.log.LogConstants;
import user.log.LogGenerate;
import user.service.IUserService;
import user.vo.Response;
import user.vo.User;

import javax.servlet.http.HttpServletRequest;

/**
 *创建用户服务
 */
@Slf4j
@RestController
@RequestMapping("/passbook")
public class CreateUserController {

    /** 创建用户服务*/
    private final IUserService userService;
    private final HttpServletRequest request;
    @Autowired
    public CreateUserController(IUserService userService, HttpServletRequest request) {
        this.userService = userService;
        this.request = request;
    }

    /**
     *创建用户
     * @param user {@link User}
     * @return {@link Response}
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/createuser")
    Response createUser(@RequestBody User user) throws Exception{

        LogGenerate.getLog(
                request,
                -1L,
                LogConstants.AcitonName.CREATE_USER,
                user
        );
        return userService.createUser(user);
    }
}
